﻿namespace SupportSystemDB
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Members Controller Class.
    /// </summary>
    public class MemberController : ParentController
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MemberController"/> class.
        /// </summary>
        /// <param name="databaseAccess">The database access.</param>
        internal MemberController( SupportEntities databaseAccess ): base( databaseAccess )
        {
        }

        /// <summary>
        /// Logins the specified user.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <returns>LoginResults Enumerator Value</returns>
        public LogInResults Login(string userName,string password)
        {
            return (LogInResults)this.SupportDB.LoginCheck( userName , password ).FirstOrDefault();
        }

        /// <summary>
        /// Gets the current user.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <returns>Current Member Data</returns>
        public vMember GetCurrentUser (string userName)
        {
            return this.SupportDB.GetMemberByUserName( userName ).FirstOrDefault();
        }

        /// <summary>
        /// Gets the specified member.
        /// </summary>
        /// <param name="memberId">The member id.</param>
        /// <returns>Member's Data</returns>
        public vMember Get (int memberId)
        {
            return this.SupportDB.GetMemberById( memberId ).FirstOrDefault();
        }

        /// <summary>
        /// Participation in events.
        /// </summary>
        /// <param name="memberId">The member id.</param>
        /// <returns>Participation Information foreach Event</returns>
        public List<vParticipate> ParticipateInEvent( int memberId )
        {
            return this.SupportDB.GetMemberParticipationInEvents( memberId ).ToList();
        }

        /// <summary>
        /// Gets the members in specified event.
        /// </summary>
        /// <param name="eventId">The event id.</param>
        /// <returns>List of members participated in the event</returns>
        public List<vMember> GetMembers( int eventId )
        {
            return this.SupportDB.GetMembersByEvent( eventId ).ToList();
        }

        /// <summary>
        /// Gets the contacts of member.
        /// </summary>
        /// <param name="memberId">The member id.</param>
        /// <returns>List of Contact details for member</returns>
        public List<vContact> GetContacts(int memberId)
        {
            return this.SupportDB.GetMemberContacts( memberId ).ToList();
        }

        /// <summary>
        /// Gets the active members.
        /// </summary>
        /// <returns>List of active members</returns>
        public List<vMember> GetActiveMembers()
        {
            return this.SupportDB.GetActiveMembers().ToList();
        }
    }
}
